package com.example.sneakerappserver.service;

import com.example.sneakerappserver.pojo.Order;
import com.example.sneakerappserver.pojo.User;
import com.example.sneakerappserver.pojo.dto.OrderDto;
import com.example.sneakerappserver.repository.OrderRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService implements IOrderService{

    @Autowired
    OrderRepository orderRepository;
    @Override
    public void update(Order order) {
        orderRepository.save(order);    // 更新订单状态
    }

    @Override
    public Order add(Order order) {
        return orderRepository.save(order);
    }

    @Override
    public Order queryByOrderId(Long orderId) {
        return orderRepository.findByOrderId(orderId); // 返回一个Order对象
    }

    @Override
    public List<Order> queryByUserId(Long userId) {
        return orderRepository.findByUserId(userId);
    }

    @Override
    public List<Order> queryByUserIdAndStatus(Long userId, String status) {
        return orderRepository.findByUserIdAndStatus(userId, status);
    }

    @Override
    public List<Order> queryByStatus(String status) {
        return orderRepository.findByStatus(status);
    }

    @Override
    public void deleteOrder(Order o) {
        orderRepository.delete(o);
    }

    @Override
    public boolean existsById(Long orderId) {
        return orderRepository.existsById(orderId);
    }


}
